package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// AlarmNotifyRule 通知规则
type AlarmNotifyRule struct {
	ID           string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	Name         string `json:"name" gorm:"column:name;type:string;size:40;uniqueIndex:rule_name;comment:规则名称"`
	MerchantID   string `json:"merchant_id,omitempty" gorm:"column:merchant_id;type:int;size:64;uniqueIndex:rule_name;comment:商户id"`
	RobotIDs     string `json:"robot_ids" gorm:"column:robot_ids;type:text;comment:设备id"`
	AlarmTypes   string `json:"alarm_types" gorm:"column:alarm_types;type:text;comment:告警类型"`
	ReceiveUsers string `json:"receive_users" gorm:"column:receive_users;type:string;size:10000:comment:接收用户"`
	NotifyTypes  string `json:"notify_types" gorm:"column:notify_types;type:string;size:100;comment:通知方式"`
	CreatedAt    int64  `json:"created_at" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
	UpdatedAt    int64  `json:"updated_at" gorm:"autoUpdateTime;column:updated_at;type:int;size:64;comment:更新时间"`
}

// TableName 表名称
func (n *AlarmNotifyRule) TableName() string {
	return "alarm_notify_rule"
}

// BeforeCreate 自增id
func (n *AlarmNotifyRule) BeforeCreate(tx *gorm.DB) (err error) {
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	n.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &AlarmNotifyRule{})
}
